package com.sxdx.dao.impl;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import com.sxdx.dao.BaseDAO;
import com.sxdx.dao.SerialcodeDAO;
import com.sxdx.entity.Serialcode;
import com.sxdx.util.SerialCodeMaker;

@SuppressWarnings("all")
@Repository("serialcodeDAO")
public class SerialcodeDAOImpl implements SerialcodeDAO{
	private static Logger logger = LogManager.getLogger(Thread.currentThread().getStackTrace()[1].getClassName());
	@Resource(name="baseDAO")
	private BaseDAO<Serialcode> baseDAO;
	
	public void saveSerialcode(int rows, int cols) {
		Serialcode serialcode=null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
		for (int i = 0; i < cols; i++) {
			serialcode= new Serialcode();
			String code = new SerialCodeMaker().getRandom(rows);
			serialcode.setRegCode(code);
			serialcode.setCodeFlag("未使用");
			serialcode.setRegTime(sdf.format(new Date()));
			baseDAO.save(serialcode);
		}
	}
	public void clsSerialcode() {
		String hql = "from Serialcode";
		List<Serialcode> codes= baseDAO.find(hql);
		for(Serialcode c:codes){
            baseDAO.delete(c);
        }
	}
	
	public Serializable save(Serialcode serialcode) {
		return baseDAO.save(serialcode);
	}
	public void delete(Serialcode serialcode) {
		baseDAO.delete(serialcode);
	}
	public void update(Serialcode serialcode) {
		baseDAO.update(serialcode);
	}
	public void saveOrUpdate(Serialcode serialcode) {
		baseDAO.saveOrUpdate(serialcode);
	}
	public List<Serialcode> find(String hql) {
		return baseDAO.find(hql);
	}
	public List<Serialcode> find(String hql, Object[] param) {
		return baseDAO.find(hql, param);
	}
	public List<Serialcode> find(String hql, List<Object> param) {
		return baseDAO.find(hql, param);
	}
	public List<Serialcode> find(String hql, Object[] param, Integer page,
			Integer rows) {
		return baseDAO.find(hql, param, page, rows);
	}
	public List<Serialcode> find(String hql, List<Object> param, Integer page,
			Integer rows) {
		return baseDAO.find(hql, param, page, rows);
	}
	public Serialcode get(Class<Serialcode> c, Serializable id) {
		return baseDAO.get(c, id);
	}
	public Serialcode get(String hql, Object[] param) {
		return baseDAO.get(hql, param);
	}
	public Serialcode get(String hql, List<Object> param) {
		return baseDAO.get(hql, param);
	}
	public Long count(String hql) {
		return baseDAO.count(hql);
	}
	public Long count(String hql, Object[] param) {
		return baseDAO.count(hql, param);
	}
	public Long count(String hql, List<Object> param) {
		return baseDAO.count(hql, param);
	}
	public Integer executeHql(String hql) {
		return baseDAO.executeHql(hql);
	}
	public Integer executeHql(String hql, Object[] param) {
		return baseDAO.executeHql(hql, param);
	}
	public Integer executeHql(String hql, List<Object> param) {
		return baseDAO.executeHql(hql, param);
	}
	
	public List<Serialcode> page(String hql, Integer offset, Integer size) {
		return baseDAO.page(hql, offset, size);
	}
	
	public Query findBySql(String sql) {
		return null;
	}

}
